<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var objA = {
				a:1,
				name:"深拷贝",
				b:null,
				c:undefined,
				d:{
					config:{
						name:'123'
					},
					like:['篮球','羽毛球']
				},
				e:[1,2,3]
			};
			var objB = {
				name:"深合并",
				d:{
					config:{
						age:'40'
					},
					num:"50"
				}
			}
			function isObject(obj){
				return toString.call(obj) ==='[object Object]'
			}
			function isArray(){
				return toString.call(obj) === '[object Array]'
			}
			function deepCopy(obj){
				let newObj = {}
				for(let key in obj){
					if(obj.hasOwnProperty(key)){
						if(isObject(obj[key])){
							newObj[key] = deepCopy(obj[key])
						}else{
							newObj[key] = obj[key]
						}
					}
				}
				return newObj
			}
			let obj = deepCopy(objA)
			console.log(obj)
			
			let objC = merge(objA,objB)
			console.log(objC)
			function merge(obj1,obj2){
				let newObj = deepCopy(obj1);
				for(let key in obj2){
					if(obj1.hasOwnProperty(key)){
						if(isObject(obj2[key])){
							newObj[key] = merge(obj1[key],obj2[key])
						}else{
							newObj[key] = obj2[key]
						}
					}else{
						newObj[key] = obj2[key]
					}
				}
				return newObj
			}
		</script>
	</body>
</html>
